<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        border: solid 5px;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <div id="d1">
      d1
      <div id="d2">
        d2
        <div id="d3">
          d3
          <div id="d4">d4</div>
        </div>
      </div>
    </div>
    <script>
      const d1 = document.getElementById("d1");
      const d2 = document.getElementById("d2");
      const d3 = document.getElementById("d3");
      const d4 = document.getElementById("d4");

      d1.onclick = () => console.log(1);
      d2.onclick = () => console.log(2);
      d3.onclick = () => console.log(3);
      d4.onclick = () => console.log(4);
      document.body.onclick = () => console.log("body");
      document.documentElement.onclick = () => console.log("html");
      document.onclick = () => console.log("document");
      window.onclick = () => console.log("window");
    </script>
  </body>
</html>
